import { getCollectInfoAPI } from '@/api/collect'
import { createSlice } from '@reduxjs/toolkit'

const collectStore = createSlice({
    name: 'collect',
    initialState: {
        collectInfo: []
    },
    reducers: {
        setCollectInfo (state, action) {
            state.collectInfo = action.payload
        }
    }
})

const {setCollectInfo} = collectStore.actions
// 获取reducer函数
const collectReducer = collectStore.reducer

// 获取消息
const fetchCollectInfo = (id) => {
    return async (dispatch) => {
      const res = await getCollectInfoAPI(id)
      dispatch(setCollectInfo(res.data))
    }
  }

export { fetchCollectInfo }

export default collectReducer